package com.cy.pj.modules.controller;

import com.cy.pj.common.vo.JsonResult;
import com.cy.pj.common.web.domain.BaseController;
import com.cy.pj.modules.entity.OrderItem;
import com.cy.pj.modules.service.IOrderItemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;


/**
 * 【请填写功能名称】Controller
 *
 * @author kiven
 * @date 2023-03-07
 */
@Controller
@RequestMapping("/orderItem")
public class OrderItemController extends BaseController
{
    private String prefix = "/orderItem";

    @Autowired
    private IOrderItemService orderItemService;

    @RequiresPermissions("orderItem:list")
    @GetMapping()
    public String item()
    {
        return prefix + "/orderItem";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("orderItem:list")
    @PostMapping("/list")
    @ResponseBody
    public JsonResult list(OrderItem orderItem,Integer pageCurrent)
    {
        return new JsonResult(orderItemService.selectOrderItemList(orderItem, pageCurrent));
    }
    //
    ///**
    // * 导出【请填写功能名称】列表
    // */
    //@RequiresPermissions("pj:item:export")
    //@Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    //@PostMapping("/export")
    //@ResponseBody
    //public AjaxResult export(OrderItem orderItem)
    //{
    //    List<OrderItem> list = orderItemService.selectOrderItemList(orderItem);
    //    ExcelUtil<OrderItem> util = new ExcelUtil<OrderItem>(OrderItem.class);
    //    return util.exportExcel(list, "item");
    //}

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("orderItem:add")
    @PostMapping("/add")
    @ResponseBody
    public JsonResult addSave(OrderItem orderItem)
    {
        return new JsonResult(orderItemService.insertOrderItem(orderItem));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        OrderItem orderItem = orderItemService.selectOrderItemById(id);
        mmap.put("orderItem", orderItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("orderItem:update")
    @PostMapping("/edit")
    @ResponseBody
    public JsonResult editSave(OrderItem orderItem)
    {
        return new JsonResult(orderItemService.updateOrderItem(orderItem));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("orderItem:delete")
    @PostMapping( "/remove")
    @ResponseBody
    public JsonResult remove(String ids)
    {
        return new JsonResult(orderItemService.deleteOrderItemByIds(ids));
    }
}
